using System.Linq;

namespace PersonalAccoutingProgram.Data
{
    partial class UserDataClassesDataContext
    {
        public static IQueryable<User> GetUserByPass(
            string username, string password)
        {
            UserDataClassesDataContext userDC = 
            new UserDataClassesDataContext();
            var user =
            from currentUser in userDC.GetTable<User>()
            where (username == currentUser.Username &&
                   currentUser.Password == password)
            select currentUser;
            return user;
        }

        public static IQueryable<User> GetUser(string username)
        {
            UserDataClassesDataContext userDC = new UserDataClassesDataContext();
            var queryResult =
            from currentUser in userDC.GetTable<User>()
            where (username == currentUser.Username)
            select currentUser;
            return queryResult;
        }

        public static IQueryable<int> GetUserID(string username)
        {
            ExpenseDataClassesDataContext expensesDC = new ExpenseDataClassesDataContext();
            var userID =
            from currentUser in expensesDC.GetTable<User>()
            where currentUser.Username == username
            select currentUser.UserID;
            return userID;
        }

        public static void RegisterNewUser(string username, string pass)
        {
            UserDataClassesDataContext userDC =
            new UserDataClassesDataContext();
            userDC.AddNewUser(username, pass);
        }
    }
}